home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-05-23 | 1.6 KB | 69 lines |
- // ChangeUser
- // A command line program for adding or editing a JFS user
- import java.io.*;
- import java.util.Vector;
-
- public class ChangeUser
- {
- public static void main(String argv[])
- {
- if (argv.length != 5) {
- System.err.println("usage: ChangeUser <JFS root> <username> "+
- "<real name> <password> <home dir>");
- System.exit(1);
- }
- FileSystem.init(argv[0]);
-
- // Read in users
- BufferInputStream ibuf = null;
- try ibuf = new BufferInputStream(
- FileSystem.getfile("/etc/users", 0, -1, -1));
- catch(BadPathException e) {
- System.err.println("Could not open /etc/users");
- System.exit(1);
- }
- Vector users = new Vector();
- try while(true) users.addElement(new JFSuser(ibuf.gets()));
- catch(IOException e);
-
- // Check if this user already exists
- JFSuser old = null;
- for(int i=0; i<users.size(); i++) {
- JFSuser u = (JFSuser)users.elementAt(i);
- if (u.name.equals(argv[1]))
- old = u;
- }
-
- if (old == null) {
- // Add the user
- JFSuser nu = new JFSuser();
- nu.name = argv[1];
- nu.realname = argv[2];
- nu.password = argv[3];
- nu.home = argv[4];
- users.addElement(nu);
- }
- else {
- // Update the user's real name and password
- old.realname = argv[2];
- old.password = argv[3];
- }
-
- // Write out user's file
- BufferOutputStream obuf = new BufferOutputStream();
- for(int i=0; i<users.size(); i++)
- obuf.puts(((JFSuser)users.elementAt(i)).output());
- try FileSystem.putfile("/etc/users", 0, obuf.getarray(),
- "root", "text/plain");
- catch(BadPathException e) {
- System.err.println("Failed to write /etc/users");
- System.exit(1);
- }
-
- // Create home dir
- try FileSystem.mkdir(argv[4], argv[1]);
- catch(BadPathException e);
- }
- }
-
-